package com.bwie.bargain.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.bwie.bargain.entity.BargainbetweenEntity;
import com.bwie.bargain.entity.TakenotesEntity;
import com.bwie.bargain.feign.UserFeignService;
import com.bwie.bargain.vo.BargainVo;
import com.bwie.bargain.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bwie.bargain.entity.BargainEntity;
import com.bwie.bargain.service.BargainService;
import com.bwie.miaosha.common.utils.PageUtils;
import com.bwie.miaosha.common.utils.R;



/**
 * 
 *
 * @author HouDing
 * @email 1398853436@qq.com
 * @date 2022-03-09 20:02:51
 */
@RestController
@RequestMapping("bargain/bargain")
public class BargainController {
    @Autowired
    private BargainService bargainService;
    @Autowired
    private UserFeignService userFeignService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bargainService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("checkUser/{userId}")
    public R CheckUser(@PathVariable("userId") Long userId) {
        UserVo userVo = bargainService.findByUserId(userId);
        return R.ok().put("userVo",userVo);
    }

    @RequestMapping("/add")
    public R add(@RequestParam("uid")Long uid,@RequestBody BargainVo bargainVo){
        bargainService.add(uid,bargainVo);
        return R.ok();
    }
    @RequestMapping("/getLink")
    public R getLink(@RequestParam("userId")Long userId,@RequestParam("id")Long id,
                     @RequestParam("helpId")Long helpId) {
        return bargainService.getLink(userId,id,helpId);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{bargainId}")
    public R info(@PathVariable("bargainId") Long bargainId){
		BargainEntity bargain = bargainService.getById(bargainId);
        return R.ok().put("bargain", bargain);
    }
    @RequestMapping("/bargainList")
    public R bargainList() {
        List<BargainVo> bargainVos = bargainService.barginList();
        return R.ok().put("bargainList",bargainVos);
    }

    @RequestMapping("/hui/{bargainId}")
    public R huixian(@PathVariable("bargainId") Long bargainId){
        BargainVo bargainVo = bargainService.findByBargainId(bargainId);
        return R.ok().put("bargain", bargainVo);
    }
    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody BargainEntity bargain){
		bargainService.save(bargain);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody BargainEntity bargain){
		bargainService.updateById(bargain);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] bargainIds){
		bargainService.removeByIds(Arrays.asList(bargainIds));
        return R.ok();
    }

}
